import 'dart:math';

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: ArcDemo(),
    );
  }
}

class ArcDemo extends StatefulWidget {
  @override
  _ArcDemoState createState() => _ArcDemoState();
}

class _ArcDemoState extends State<ArcDemo> {
  Offset? _clickOffset;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('绘制专题')),
      body: Center(
        child: Container(
          width: 500,
          height: 500,
          color: Colors.blue.shade100,
          child: CustomPaint(
            size: Size(500, 500),
            //画布
            //绘制工作
            painter: RectPainter(),
          ),
        ),
      ),
    );
  }
}

class RectPainter extends CustomPainter {
  Paint _paint = Paint()
    //颜色
    ..color = Colors.red
    //填充方式
    ..style = PaintingStyle.fill
    //拐角的样式
    ..strokeCap = StrokeCap.round
    //宽度
    ..strokeWidth = 3;
  @override
  void paint(Canvas canvas, Size size) {
    //定义矩形
    Rect rect = Rect.fromLTWH(100, 100, 200, 150);
    _paint.color = Colors.yellow.shade50;
    canvas.drawRect(rect, _paint);

    //绘制圆弧
    _paint.color = Colors.red;
    canvas.drawArc(
      //矩形
      rect,
      //开始的弧度 0 水平
      0,
      //扫描的弧度
      degreeToRadian(60),
      //是否连接到中心点
      true,
      //画笔
      _paint,
    );
  }

  //度数与弧度 的转换
  double degreeToRadian(double degrre) => degrre * pi / 180;

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }
}
